package com.bugsnag.ohos;

import com.bugsnag.ohos.internal.ImmutableConfig;

import java.io.IOException;

/**
 * app
 *
 * @since 2021-06-29
 */
public class App implements JsonStream.Streamable {
    /**
     * The architecture of the running application binary
     */
    String binaryArch;

    /**
     * The package name of the application
     */
    String id;

    /**
     * The release stage set in [Configuration.releaseStage]
     */
    String releaseStage;

    /**
     * The version of the application set in [Configuration.version]
     */
    String version;
    /**
     * The revision ID from the manifest (React Native apps only)
     */
    String codeBundleId;

    /**
     * The unique identifier for the build of the application set in [Configuration.buildUuid]
     */
    String buildUuid;

    /**
     * The application type set in [Configuration#version]
     */
    String type;

    /**
     * The version code of the application set in [Configuration.versionCode]
     */
    Number versionCode;

    /**
     * constructor
     *
     * @param binaryArch
     * @param id
     * @param releaseStage
     * @param version
     * @param codeBundleId
     * @param buildUuid
     * @param type
     * @param versionCode
     */
    public App(String binaryArch, String id, String releaseStage, String version,
               String codeBundleId, String buildUuid, String type, Number versionCode) {
        this.binaryArch = binaryArch;
        this.id = id;
        this.releaseStage = releaseStage;
        this.version = version;
        this.codeBundleId = codeBundleId;
        this.buildUuid = buildUuid;
        this.type = type;
        this.versionCode = versionCode;
    }

    /**
     * constructor
     *
     * @param config
     * @param binaryArch
     * @param id
     * @param releaseStage
     * @param version
     * @param codeBundleId
     */
    public App(ImmutableConfig config, String binaryArch, String id, String releaseStage, String version,
               String codeBundleId) {
        this(
            binaryArch,
            id,
            releaseStage,
            version,
            codeBundleId,
            config.getBuildUuid(),
            config.getAppType(),
            config.getVersionCode()
        );
    }

    @Override
    public void toStream(JsonStream writer) throws IOException {
        writer.beginObject();
        serialiseFields(writer);
        writer.endObject();
    }

    /**
     * serialise Fields
     *
     * @param writer
     * @throws IOException
     */
    public void serialiseFields(JsonStream writer) throws IOException {
        writer.name("binaryArch").value(binaryArch);
        writer.name("buildUUID").value(buildUuid);
        writer.name("codeBundleId").value(codeBundleId);
        writer.name("id").value(id);
        writer.name("releaseStage").value(releaseStage);
        writer.name("type").value(type);
        writer.name("version").value(version);
        writer.name("versionCode").value(versionCode);
    }

    public String getBinaryArch() {
        return binaryArch;
    }

    public void setBinaryArch(String binaryArch) {
        this.binaryArch = binaryArch;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getReleaseStage() {
        return releaseStage;
    }

    public void setReleaseStage(String releaseStage) {
        this.releaseStage = releaseStage;
    }

    public String getVersion() {
        return version;
    }

    public void setVersion(String version) {
        this.version = version;
    }

    public String getCodeBundleId() {
        return codeBundleId;
    }

    public void setCodeBundleId(String codeBundleId) {
        this.codeBundleId = codeBundleId;
    }

    public String getBuildUuid() {
        return buildUuid;
    }

    public void setBuildUuid(String buildUuid) {
        this.buildUuid = buildUuid;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public Number getVersionCode() {
        return versionCode;
    }

    public void setVersionCode(Number versionCode) {
        this.versionCode = versionCode;
    }
}
